<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回匹配模式的数组条目</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.preg-grep" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">preg_grep</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">preg_grep</span> &mdash; <span class="dc-title">返回匹配模式的数组条目</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.preg-grep-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>preg_grep</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$input</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>
  ] ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
  返回给定数组<code class="parameter">input</code>中与模式<code class="parameter">pattern</code>
  匹配的元素组成的数组.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.preg-grep-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">pattern</code></dt>

     <dd>

      <p class="para">
       要搜索的模式, 字符串形式.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">input</code></dt>

     <dd>

      <p class="para">
       输入数组.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
      如果设置为<strong><code>PREG_GREP_INVERT</code></strong>, 这个函数返回输入数组中与
      给定模式<code class="parameter">pattern</code><em class="emphasis">不</em>匹配的元素组成的数组.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.preg-grep-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
  返回使用<code class="parameter">input</code>中key做索引的数组.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.preg-grep-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5857">
    <p><strong>Example #1 <span class="function"><strong>preg_grep()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;返回所有包含浮点数的元素<br /></span><span style="color: #0000BB">$fl_array&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_grep</span><span style="color: #007700">(</span><span style="color: #DD0000">"/^(\d+)?\.\d+$/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>



 <div class="refsect1 seealso" id="refsect1-function.preg-grep-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="pcre.pattern.html" class="link">PCRE 模式</a></li>
    <li class="member"><span class="function"><a href="preg_quote.html" class="function" rel="rdfs-seeAlso">preg_quote()</a> - 转义正则表达式字符</span></li>
    <li class="member"><span class="function"><a href="preg_match_all.html" class="function" rel="rdfs-seeAlso">preg_match_all()</a> - 执行一个全局正则表达式匹配</span></li>
    <li class="member"><span class="function"><a href="preg_filter.html" class="function" rel="rdfs-seeAlso">preg_filter()</a> - 执行一个正则表达式搜索和替换</span></li>
    <li class="member"><span class="function"><a href="preg_last_error.html" class="function" rel="rdfs-seeAlso">preg_last_error()</a> - 返回最后一个PCRE正则执行产生的错误代码</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>